package com.zhuhanpeng.cloud.api.service.impl;

import com.zhuhanpeng.cloud.api.entity.ApiUserEntity;
import com.zhuhanpeng.cloud.api.entity.SearchApiUserEntity;
import com.zhuhanpeng.cloud.api.repository.ApiDao;
import com.zhuhanpeng.cloud.api.service.ApiService;
import com.zhuhanpeng.cloud.login.repository.LoginDao;
import com.zhuhanpeng.cloud.mybatis.entity.PtUserEntity;
import com.zhuhanpeng.cloud.mybatis.flexigrid.PagingEntity;
import com.zhuhanpeng.cloud.spring.security.GdmtPasswordEncoder;
import com.zhuhanpeng.cloud.user.exception.PasswordError;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ApiServiceImpl implements ApiService {
    @Resource
    private ApiDao aDao;

    @Resource
    private LoginDao loginDao;

    @Resource
    private GdmtPasswordEncoder gdmtPasswordEncoder;

    public List<PtUserEntity> queryUserInfo(SearchApiUserEntity entity, PagingEntity pagingEntity) {
        return aDao.queryUserInfo(entity,pagingEntity);
    }

    @Override
    public Integer queryUserInfoTotal(SearchApiUserEntity entity) {
        return aDao.queryUserInfoTotal(entity);
    }

    @Override
    public ApiUserEntity queryUserByNameAndPassword(String userName, String password) {
        String encodePassword = gdmtPasswordEncoder.encode(password);
        ApiUserEntity entity = aDao.queryUserByNameAndPassword(userName,encodePassword);
        List<String> authList = loginDao.queryAuthList(entity.getUserUuid());
        entity.setAuthList(authList);
        return entity;
    }
}